#include "MarioGame.h"


CMarioGame::CMarioGame(HINSTANCE hInstance, char* Name, int Mode, int IsFullScreen, int FrameRate):
	CGame(hInstance,Name,Mode,IsFullScreen, FrameRate){
		G_ScreenRect.left =100;
		G_ScreenRect.top = 50;
		G_ScreenRect.right = 900;
		G_ScreenRect.bottom = 650;
		RECT r;
		r.left = 0;
		r.right = 6400;
		r.top = 0;
		r.bottom = 6400;
		QuadTree = new CQuadTree(r);
}


CMarioGame::~CMarioGame(void)
{
}

void CMarioGame::InitGame()
{
	background = new CSurface(BACKGROUND_FILE);
	CTexture* ttPlayer = new CTexture(MARIO_FILE, 6, 2, 12);
	sprPlayer = new CSprite(ttPlayer, 0, 2, 100);
	int x = 150;
	int y = 500;
	RECT rect;
	rect.left = 150;
	rect.right = 200;
	rect.top = 500;
	rect.bottom = 550;
	obj[0] = new CObjects(0, 16, D3DXVECTOR3(150, 500,0),rect);
	rect.left = 150;
	rect.right = 200;
	rect.top = 550;
	rect.bottom = 600;
	obj[1] = new CObjects(0, 24, D3DXVECTOR3(150, 550,0),rect);
	rect.left = 200;
	rect.right = 250;
	rect.top = 500;
	rect.bottom = 550;
	obj[2] = new CObjects(0, 17, D3DXVECTOR3(200, 500, 0), rect);
	x = rect.left = 200;
	rect.right = 250;
	y = rect.top = 550;
	rect.bottom = 600;
	obj[3] = new CObjects(0, 25, D3DXVECTOR3(200, 550, 0), rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = 500;
	rect.bottom = rect.top + 50;
	obj[4] = new CObjects(0, 17, D3DXVECTOR3(150, 500, 0),rect);
	rect.left = x;
	rect.right = rect.left + 50;
	y = rect.top = y + 50;
	rect.bottom = rect.top + 50;
	obj[5] = new CObjects(0, 25, D3DXVECTOR3(150, 550, 0),rect);
	x = rect.left = x + 50;
	rect.right = rect.left + 50;
	y = rect.top = 500;
	rect.bottom = rect.top + 50;
	obj[6] = new CObjects(0, 17, D3DXVECTOR3(200, 500, 0),rect);
	rect.left = x;
	rect.right = rect.left + 50;
	y = rect.top = y + 50;
	rect.bottom = rect.top + 50;
	obj[7] = new CObjects(0, 25, D3DXVECTOR3(200, 550, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = 500;
	rect.bottom = rect.top + 50;
	obj[8] = new CObjects(0, 17, D3DXVECTOR3(250, 500, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = y + 50;
	rect.bottom = rect.top + 50;
	obj[9] = new CObjects(0, 25, D3DXVECTOR3(250, 550, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = 500;
	rect.bottom = rect.top + 50;
	obj[10] = new CObjects(0, 17, D3DXVECTOR3(300, 500, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = y + 50;
	rect.bottom = rect.top + 50;
	obj[11] = new CObjects(0, 25, D3DXVECTOR3(300, 550, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = 500;
	rect.bottom = rect.top + 50;
	obj[12] = new CObjects(0, 17, D3DXVECTOR3(350, 500, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = y + 50;
	rect.bottom = rect.top + 50;
	obj[13] = new CObjects(0, 25, D3DXVECTOR3(350, 550, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = 500;
	rect.bottom = rect.top + 50;
	obj[14] = new CObjects(0, 17, D3DXVECTOR3(400, 500, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = y + 50;
	rect.bottom = rect.top + 50;
	obj[15] = new CObjects(0, 25, D3DXVECTOR3(400, 550, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = 500;
	rect.bottom = rect.top + 50;
	obj[16] = new CObjects(0, 17, D3DXVECTOR3(450, 500, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = y + 50;
	rect.bottom = rect.top + 50;
	obj[17] = new CObjects(0, 25, D3DXVECTOR3(450, 550, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = 500;
	rect.bottom = rect.top + 50;
	obj[18] = new CObjects(0, 18, D3DXVECTOR3(500, 500, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = y + 50;
	rect.bottom = rect.top + 50;
	obj[19] = new CObjects(0, 26, D3DXVECTOR3(500, 550, 0),rect);
	x = rect.left = x+50;
	rect.right = rect.left + 50;
	y = rect.top = 500;
	rect.bottom = rect.top + 50;
	//obj[20] = new CObjects(2, 10, D3DXVECTOR3(150, 300, 0),rect);
	//obj[21] = new CObjects(2, 9, D3DXVECTOR3(100, 250, 0),rect);
	enemy = new CEnemy();
	StaObj = new CStaticObjects();
	obj[20] = new CDynamicObjects(1, 0, D3DXVECTOR3(200, 400,0),rect,0,0,0);
	for(int i = 0 ; i<21; i++)
	{
		QuadTree->Insert(obj[i]);
	}
}

void CMarioGame::Update(int Delta)
{
	//sprPlayer->Update(Delta);
	QuadTree->Move(G_ScreenRect);
}

void CMarioGame::RenderFrame(){
	// Background
	G_SpriteHandler->Begin(D3DXSPRITE_ALPHABLEND);
	background->Draw();
	sprPlayer->Draw(200,200);
	for(int i = 0 ; i<20; i++)
	{
		StaObj->Render(obj[i]);
	}
	sprPlayer->Draw(200,200);
	enemy->Render(obj[20]);
	G_SpriteHandler->End();
}

void CMarioGame::ProcessInput()
{
}

void CMarioGame::OnKeyDown(int KeyCode)
{
}
